/**
 * Copyright (C) 2010 DustedPixels.com
 */
package com.dustedpixels.cirt.model.cpu.z80;

import com.dustedpixels.cirt.model.core.Circuit;
import com.dustedpixels.cirt.model.core.In;
import com.dustedpixels.cirt.model.core.Internal;
import com.dustedpixels.cirt.model.core.Out;
import com.dustedpixels.cirt.model.core.Script;

/**
 * A register with flags.
 *
 * @author Michal Pociecha-Los (micapolos@gmail.com)
 */
@Circuit
public final class FlagsReg {
  @In public boolean inS;
  @In public boolean inZ;
  @In public boolean inY;
  @In public boolean inH;
  @In public boolean inX;
  @In public boolean inP;
  @In public boolean inN;
  @In public boolean inC;

  @In public boolean writeS;
  @In public boolean writeZ;
  @In public boolean writeY;
  @In public boolean writeH;
  @In public boolean writeX;
  @In public boolean writeP;
  @In public boolean writeN;
  @In public boolean writeC;

  @Out public boolean outS;
  @Out public boolean outZ;
  @Out public boolean outY;
  @Out public boolean outH;
  @Out public boolean outX;
  @Out public boolean outP;
  @Out public boolean outN;
  @Out public boolean outC;

  @Internal public boolean s;
  @Internal public boolean z;
  @Internal public boolean y;
  @Internal public boolean h;
  @Internal public boolean x;
  @Internal public boolean p;
  @Internal public boolean n;
  @Internal public boolean c;
  
  @Script
  public void update() {
    if (writeS) s = inS;
    if (writeZ) z = inZ;
    if (writeY) y = inY;
    if (writeH) h = inH;
    if (writeX) x = inX;
    if (writeP) p = inP;
    if (writeN) n = inN;
    if (writeC) c = inC;
    
    outS = s;
    outZ = z;
    outY = y;
    outH = h;
    outX = x;
    outP = p;
    outN = n;
    outC = c;
  }
}
